package org.ljy.springblog.model;
//作为结果返回的实体类

import lombok.Data;
import org.ljy.springblog.enums.ResultCodeEnum;

@Data
public class Result<T> {
    public int code;
    public String msg;
    public T data;

    //1.成功情况
    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        return result;
    }
    //2.未登录
    public static <T> Result nologin() {
        Result result = new Result();
        result.setCode(ResultCodeEnum.NO_LOGIN.getCode());
        result.setMsg("未登录");
        return result;
    }

    //3.请求失败
    public static <T> Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMsg(errMsg);
        return result;
    }
    public static <T> Result fail(String errMsg,T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setData(data);
        result.setMsg(errMsg);
        return result;
    }
    public static <T> Result fail(int code,String errMsg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(errMsg);
        return result;
    }
    public static <T> Result fail(String errMsg,int code,T data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(errMsg);
        result.setData(data);
        return result;
    }
}
